// Copyright 2021 Rockchip Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "common.h"
#include "video.h"

// Font : 32x32 Horizontal modulus left high position
const unsigned char ASIICTable[] = {
    /* Arial */
    /*  0[0x0030]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x07,
    0xE0,
    0x00,
    0x00,
    0x1F,
    0xF8,
    0x00,
    0x00,
    0x3F,
    0xFC,
    0x00,
    0x00,
    0x7C,
    0x3C,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0x7C,
    0x3E,
    0x00,
    0x00,
    0x3F,
    0xFC,
    0x00,
    0x00,
    0x1F,
    0xF8,
    0x00,
    0x00,
    0x07,
    0xE0,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /*  1[0x0031]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x30,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0xF0,
    0x00,
    0x00,
    0x01,
    0xF0,
    0x00,
    0x00,
    0x07,
    0xF0,
    0x00,
    0x00,
    0x0F,
    0x70,
    0x00,
    0x00,
    0x1E,
    0x70,
    0x00,
    0x00,
    0x18,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /*  2[0x0032]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x0F,
    0xE0,
    0x00,
    0x00,
    0x3F,
    0xF8,
    0x00,
    0x00,
    0x7F,
    0xFC,
    0x00,
    0x00,
    0x78,
    0x3C,
    0x00,
    0x00,
    0xE0,
    0x1E,
    0x00,
    0x00,
    0xE0,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x1C,
    0x00,
    0x00,
    0x00,
    0x1C,
    0x00,
    0x00,
    0x00,
    0x38,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0xE0,
    0x00,
    0x00,
    0x01,
    0xC0,
    0x00,
    0x00,
    0x07,
    0x80,
    0x00,
    0x00,
    0x0F,
    0x00,
    0x00,
    0x00,
    0x1C,
    0x00,
    0x00,
    0x00,
    0x38,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x7F,
    0xFE,
    0x00,
    0x00,
    0xFF,
    0xFE,
    0x00,
    0x00,
    0xFF,
    0xFE,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /*  3[0x0033]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x07,
    0xE0,
    0x00,
    0x00,
    0x1F,
    0xF8,
    0x00,
    0x00,
    0x3F,
    0xFC,
    0x00,
    0x00,
    0x78,
    0x3C,
    0x00,
    0x00,
    0xF0,
    0x0E,
    0x00,
    0x00,
    0xE0,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x1E,
    0x00,
    0x00,
    0x00,
    0x3C,
    0x00,
    0x00,
    0x03,
    0xF8,
    0x00,
    0x00,
    0x03,
    0xF8,
    0x00,
    0x00,
    0x03,
    0xFC,
    0x00,
    0x00,
    0x00,
    0x1E,
    0x00,
    0x00,
    0x00,
    0x0F,
    0x00,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xF0,
    0x0E,
    0x00,
    0x00,
    0x78,
    0x1E,
    0x00,
    0x00,
    0x3F,
    0xFC,
    0x00,
    0x00,
    0x1F,
    0xF8,
    0x00,
    0x00,
    0x07,
    0xE0,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /*  4[0x0034]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x18,
    0x00,
    0x00,
    0x00,
    0x38,
    0x00,
    0x00,
    0x00,
    0x78,
    0x00,
    0x00,
    0x00,
    0xF8,
    0x00,
    0x00,
    0x00,
    0xF8,
    0x00,
    0x00,
    0x01,
    0xF8,
    0x00,
    0x00,
    0x03,
    0xB8,
    0x00,
    0x00,
    0x07,
    0xB8,
    0x00,
    0x00,
    0x07,
    0x38,
    0x00,
    0x00,
    0x0E,
    0x38,
    0x00,
    0x00,
    0x1C,
    0x38,
    0x00,
    0x00,
    0x1C,
    0x38,
    0x00,
    0x00,
    0x38,
    0x38,
    0x00,
    0x00,
    0x70,
    0x38,
    0x00,
    0x00,
    0xE0,
    0x38,
    0x00,
    0x00,
    0xFF,
    0xFF,
    0x00,
    0x00,
    0xFF,
    0xFF,
    0x00,
    0x00,
    0xFF,
    0xFF,
    0x00,
    0x00,
    0x00,
    0x38,
    0x00,
    0x00,
    0x00,
    0x38,
    0x00,
    0x00,
    0x00,
    0x38,
    0x00,
    0x00,
    0x00,
    0x38,
    0x00,
    0x00,
    0x00,
    0x38,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /*  5[0x0035]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x3F,
    0xFE,
    0x00,
    0x00,
    0x3F,
    0xFE,
    0x00,
    0x00,
    0x3F,
    0xFE,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0x73,
    0xE0,
    0x00,
    0x00,
    0x6F,
    0xF8,
    0x00,
    0x00,
    0xFF,
    0xFC,
    0x00,
    0x00,
    0xF8,
    0x1E,
    0x00,
    0x00,
    0xE0,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xF0,
    0x0E,
    0x00,
    0x00,
    0x78,
    0x1E,
    0x00,
    0x00,
    0x7F,
    0xFC,
    0x00,
    0x00,
    0x1F,
    0xF8,
    0x00,
    0x00,
    0x0F,
    0xE0,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /*  6[0x0036]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x03,
    0xF0,
    0x00,
    0x00,
    0x0F,
    0xFC,
    0x00,
    0x00,
    0x1F,
    0xFE,
    0x00,
    0x00,
    0x3C,
    0x1E,
    0x00,
    0x00,
    0x78,
    0x0F,
    0x00,
    0x00,
    0x70,
    0x07,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0xE0,
    0x00,
    0x00,
    0x00,
    0xE3,
    0xF0,
    0x00,
    0x00,
    0xEF,
    0xF8,
    0x00,
    0x00,
    0xFF,
    0xFC,
    0x00,
    0x00,
    0xFC,
    0x1E,
    0x00,
    0x00,
    0xF0,
    0x0F,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0x70,
    0x07,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0x3C,
    0x1E,
    0x00,
    0x00,
    0x3F,
    0xFC,
    0x00,
    0x00,
    0x0F,
    0xF8,
    0x00,
    0x00,
    0x07,
    0xE0,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /*  7[0x0037]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0xFF,
    0xFE,
    0x00,
    0x00,
    0xFF,
    0xFE,
    0x00,
    0x00,
    0xFF,
    0xFE,
    0x00,
    0x00,
    0x00,
    0x0C,
    0x00,
    0x00,
    0x00,
    0x18,
    0x00,
    0x00,
    0x00,
    0x38,
    0x00,
    0x00,
    0x00,
    0x70,
    0x00,
    0x00,
    0x00,
    0xE0,
    0x00,
    0x00,
    0x00,
    0xE0,
    0x00,
    0x00,
    0x01,
    0xC0,
    0x00,
    0x00,
    0x01,
    0xC0,
    0x00,
    0x00,
    0x03,
    0x80,
    0x00,
    0x00,
    0x03,
    0x80,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0x00,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x0E,
    0x00,
    0x00,
    0x00,
    0x1C,
    0x00,
    0x00,
    0x00,
    0x1C,
    0x00,
    0x00,
    0x00,
    0x1C,
    0x00,
    0x00,
    0x00,
    0x1C,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /*  8[0x0038]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x07,
    0xE0,
    0x00,
    0x00,
    0x1F,
    0xF8,
    0x00,
    0x00,
    0x3F,
    0xFC,
    0x00,
    0x00,
    0x78,
    0x1C,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0x38,
    0x1C,
    0x00,
    0x00,
    0x1F,
    0xF8,
    0x00,
    0x00,
    0x0F,
    0xF0,
    0x00,
    0x00,
    0x3F,
    0xFC,
    0x00,
    0x00,
    0x78,
    0x1E,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xF0,
    0x0F,
    0x00,
    0x00,
    0x78,
    0x1E,
    0x00,
    0x00,
    0x3F,
    0xFC,
    0x00,
    0x00,
    0x1F,
    0xF8,
    0x00,
    0x00,
    0x07,
    0xE0,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /*  9[0x0039]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x07,
    0xE0,
    0x00,
    0x00,
    0x1F,
    0xF0,
    0x00,
    0x00,
    0x3F,
    0xFC,
    0x00,
    0x00,
    0x78,
    0x1C,
    0x00,
    0x00,
    0x70,
    0x0E,
    0x00,
    0x00,
    0xE0,
    0x06,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xE0,
    0x07,
    0x00,
    0x00,
    0xF0,
    0x0F,
    0x00,
    0x00,
    0x78,
    0x1F,
    0x00,
    0x00,
    0x3F,
    0xFF,
    0x00,
    0x00,
    0x1F,
    0xF7,
    0x00,
    0x00,
    0x0F,
    0xC7,
    0x00,
    0x00,
    0x00,
    0x07,
    0x00,
    0x00,
    0x00,
    0x0E,
    0x00,
    0x00,
    0xE0,
    0x0E,
    0x00,
    0x00,
    0xF0,
    0x1E,
    0x00,
    0x00,
    0x78,
    0x3C,
    0x00,
    0x00,
    0x7F,
    0xF8,
    0x00,
    0x00,
    0x3F,
    0xF0,
    0x00,
    0x00,
    0x0F,
    0xC0,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /*  .[0x002E]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x03,
    0x80,
    0x00,
    0x00,
    0x03,
    0x80,
    0x00,
    0x00,
    0x03,
    0x80,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /* 毫[0x6BEB]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x04,
    0x00,
    0x00,
    0x00,
    0x03,
    0x00,
    0x00,
    0x00,
    0x03,
    0x00,
    0x60,
    0x3F,
    0xFF,
    0xFF,
    0xF0,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x04,
    0x00,
    0x01,
    0xFF,
    0xFE,
    0x00,
    0x01,
    0x80,
    0x06,
    0x00,
    0x01,
    0x80,
    0x06,
    0x00,
    0x01,
    0x80,
    0x06,
    0x00,
    0x01,
    0xFF,
    0xFE,
    0x00,
    0x01,
    0x80,
    0x04,
    0x00,
    0x12,
    0x00,
    0x00,
    0x10,
    0x1F,
    0xFF,
    0xFF,
    0xF8,
    0x30,
    0x00,
    0x02,
    0x30,
    0x70,
    0x00,
    0x1F,
    0x20,
    0x60,
    0x0F,
    0xFC,
    0xC0,
    0x0F,
    0xF6,
    0x00,
    0x00,
    0x00,
    0x06,
    0x06,
    0x00,
    0x00,
    0x07,
    0xFF,
    0x00,
    0x0F,
    0xFE,
    0x00,
    0x80,
    0x00,
    0x06,
    0x01,
    0xC0,
    0x00,
    0x1F,
    0xFF,
    0xB0,
    0x3F,
    0xE6,
    0x00,
    0x10,
    0x00,
    0x06,
    0x00,
    0x10,
    0x00,
    0x06,
    0x00,
    0x10,
    0x00,
    0x07,
    0xFF,
    0xB8,
    0x00,
    0x03,
    0xFF,
    0xF0,
    0x00,
    0x00,
    0x00,
    0x00,
    /* Arial */
    /* 秒[0x79D2]   32x32 */
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x04,
    0x00,
    0x00,
    0x38,
    0x06,
    0x00,
    0x00,
    0xFC,
    0x06,
    0x00,
    0x1F,
    0x80,
    0x06,
    0x00,
    0x01,
    0x80,
    0x06,
    0x00,
    0x01,
    0x80,
    0x06,
    0x00,
    0x01,
    0x80,
    0x06,
    0x80,
    0x01,
    0x80,
    0xE6,
    0x60,
    0x01,
    0x88,
    0xC6,
    0x30,
    0x3F,
    0xFC,
    0xC6,
    0x18,
    0x01,
    0x80,
    0x86,
    0x0C,
    0x01,
    0x80,
    0x86,
    0x0C,
    0x03,
    0x81,
    0x86,
    0x08,
    0x03,
    0xF1,
    0x06,
    0x00,
    0x03,
    0xB9,
    0x06,
    0x00,
    0x07,
    0x9A,
    0x06,
    0x30,
    0x05,
    0x9A,
    0x06,
    0x38,
    0x09,
    0x84,
    0x06,
    0x60,
    0x19,
    0x80,
    0x06,
    0xE0,
    0x11,
    0x80,
    0x05,
    0xC0,
    0x21,
    0x80,
    0x01,
    0x80,
    0x41,
    0x80,
    0x03,
    0x00,
    0x01,
    0x80,
    0x06,
    0x00,
    0x01,
    0x80,
    0x1C,
    0x00,
    0x01,
    0x80,
    0x30,
    0x00,
    0x01,
    0x80,
    0xE0,
    0x00,
    0x01,
    0x83,
    0x80,
    0x00,
    0x01,
    0x9C,
    0x00,
    0x00,
    0x01,
    0x20,
    0x00,
    0x00,
};

const unsigned char ASIICTable[];
unsigned char *get_assiic_table(char c) {
	unsigned char *ASIICTable_x;
	switch (c) {
	case '0':
		ASIICTable_x = (unsigned char *)&ASIICTable[0];
		break;
	case '1':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 1];
		break;
	case '2':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 2];
		break;
	case '3':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 3];
		break;
	case '4':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 4];
		break;
	case '5':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 5];
		break;
	case '6':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 6];
		break;
	case '7':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 7];
		break;
	case '8':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 8];
		break;
	case '9':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 9];
		break;
	case '.':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 10];
		break;
	case 'm':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 11];
		break;
	case 's':
		ASIICTable_x = (unsigned char *)&ASIICTable[32 * 32 / 8 * 12];
		break;
	case '?':
	default:
		ASIICTable_x = NULL;
		break;
	}
	LOG_INFO("ASIICTable_x is 0x%p\n", ASIICTable_x);
	return ASIICTable_x;
}

// uart
void read_timestamp_from_uart(char *timestamp_char) {
	int fd;
	int baud = B115200;
	struct termios newtio;
	struct serial_rs485 rs485;

	fd = open("/dev/ttyS5", O_RDWR);
	if (fd < 0) {
		LOG_INFO("Error opening serial port\n");
		return;
	}

	bzero(&newtio, sizeof(newtio)); /* clear struct for new port settings */

	/* man termios get more info on below settings */
	newtio.c_cflag = baud | CS8 | CLOCAL | CREAD;
	newtio.c_iflag = 0;
	newtio.c_oflag = 0;
	newtio.c_lflag = 0;
	// block for up till 128 characters
	newtio.c_cc[VMIN] = 4;
	// 0.5 seconds read timeout
	newtio.c_cc[VTIME] = 1;
	/* now clean the modem line and activate the settings for the port */
	tcflush(fd, TCIOFLUSH);
	tcsetattr(fd, TCSANOW, &newtio);
	if (ioctl(fd, TIOCGRS485, &rs485) >= 0) {
		/* disable RS485 */
		rs485.flags &= ~(SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND);
		rs485.delay_rts_after_send = 0;
		rs485.delay_rts_before_send = 0;
		if (ioctl(fd, TIOCSRS485, &rs485) < 0) {
			perror("Error setting RS-232 mode");
		}
	}

	/*
	 * The flag ASYNC_SPD_CUST might have already been set, so
	 * clear it to avoid confusing the kernel uart dirver.
	 */
	struct serial_struct ss;
	if (ioctl(fd, TIOCGSERIAL, &ss) < 0) {
		// return silently as some devices do not support TIOCGSERIAL
		LOG_INFO("return silently as some devices do not support TIOCGSERIAL\n");
		return;
	}
	// if ((ss.flags & ASYNC_SPD_MASK) != ASYNC_SPD_CUST)
	// 	return;
	ss.flags &= ~ASYNC_SPD_MASK;
	if (ioctl(fd, TIOCSSERIAL, &ss) < 0) {
		LOG_INFO("TIOCSSERIAL failed");
		return;
	}

	// write
	int written = write(fd, "\x67\x74", 2); // gt
	if (written < 0)
		LOG_INFO("write()");
	else
		LOG_INFO("written is %d\n", written);
	// read
	char read_buffer[4];
	int read_num = read(fd, &read_buffer, 4);
	if (read_num < 4)
		LOG_INFO("read_num is %d\n", read_num);
	else {
		LOG_INFO("read_num is %d, read_buffer is 0x%x 0x%x 0x%x 0x%x\n", read_num, read_buffer[0],
		         read_buffer[1], read_buffer[2], read_buffer[3]);
		int timestamp = (int)read_buffer[2] | ((int)read_buffer[3] << 8);
		LOG_INFO("timestamp is %d\n", timestamp);
		timestamp_char[2] = timestamp % 10 + '0';
		timestamp_char[1] = timestamp / 10 % 10 + '0';
		timestamp_char[0] = timestamp / 100 % 10 + '0';
		LOG_INFO("timestamp_char is %s\n", timestamp_char);
	}
}

#define TEST_ARGB32_RED 0xFFFF0033
#define TEST_ARGB32_TRANS 0x00000000

void draw_buffer(RK_U32 *ColorData, char *timestamp_char) {
	unsigned char *ASIICTable_0 = NULL;
	unsigned char *ASIICTable_1 = NULL;
	unsigned char *ASIICTable_2 = NULL;
	unsigned char *ASIICTable_3 = NULL;
	unsigned char *ASIICTable_4 = NULL;
	unsigned char *ASIICTable_total;
	ASIICTable_total = malloc(32 * 32 / 8 * 5 * 2); // 160 * 4
	memset(ASIICTable_total, 0, 32 * 32 / 8 * 5 * 2);
	ASIICTable_0 = get_assiic_table(timestamp_char[0]);
	ASIICTable_1 = get_assiic_table(timestamp_char[1]);
	ASIICTable_2 = get_assiic_table(timestamp_char[2]);
	ASIICTable_3 = get_assiic_table('m');
	ASIICTable_4 = get_assiic_table('s');
	LOG_INFO("ASIICTable_total is 0x%p\n", ASIICTable_total);

	// splice
	for (int i = 0; i < 32; i++) {                                  // for per line
		memcpy(ASIICTable_total + i * 20, ASIICTable_0 + i * 4, 4); // 4byte = 32bit
		memcpy(ASIICTable_total + i * 20 + 4, ASIICTable_1 + i * 4, 4);
		memcpy(ASIICTable_total + i * 20 + 8, ASIICTable_2 + i * 4, 4);
		memcpy(ASIICTable_total + i * 20 + 12, ASIICTable_3 + i * 4, 4);
		memcpy(ASIICTable_total + i * 20 + 16, ASIICTable_4 + i * 4, 4);
	}

	// debug
	// for (int i = 0; i < 32 * 32 * 5 / 8; i++) {
	//   LOG_INFO("0x%02x,", ASIICTable_total[i]);
	//   if (!((i + 1) % 16))
	//     LOG_INFO("\n");
	// }

	for (int i = 0; i < 32 * 32 * 5 / 8; i++) {
		for (int j = 0; j < 8; j++) {
			if (ASIICTable_total[i] & (1 << (7 - j)))
				ColorData[i * 8 + j] = TEST_ARGB32_RED;
			else
				ColorData[i * 8 + j] = TEST_ARGB32_TRANS;
			// LOG_INFO("i is %d, j is %d, ColorData[%d] is 0x%x\n", i, j, i*8+j,
			// ColorData[i*8+j]);
		}
	}

	free(ASIICTable_total);
}